<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>添加管理员</title>
</head>
<body>
<form name="queryByName" action="showUser.do" method="post">
    <h1>${msg}</h1>

    <h2>添加管理员页面</h2>
    <hr>
    请输入需查询的用户名：<input type="text" name="userName"/>
    <button type="submit" onClick="return validateInput()">查询</button>
    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<a href="showAllAdminInfo.do">返回管理员类表页</a>
    <hr>
    <table>
        <tr>
            <td>序号</td>
            <td>用户名</td>
            <td>注册时间</td>
            <td>用户Email</td>
        </tr>
        <c:set var="num" value="0"/>
        <c:forEach var="user" items="${listUser}">
            <c:set var="num" value="${num+1}"/>
            <tr>
                <td>${num}</td>
                <td>${user.userName}</td>
                <td><fmt:formatDate value="${user.loginTime}" pattern="yyyy年MM月dd日 HH:mm:ss"/></td>
                <td>${user.email}</td>
                <c:if test="${user.role.code==0}">
                    <td><a href="deleteOrAddAdmin.do?adminId=${user.id}&flagValue=1"
                           onclick="return yesOrNo()">授予管理员权限</a></td>
                </c:if>
            </tr>
        </c:forEach>
    </table>
    <c:if test="${flag eq true}">
        <c:if test="${pageCurId gt 1}">
            <a href="/adminLog/showAllUserInfo.do?pageCurId=${pageCurId-1}">上一页</a>
        </c:if>
        <c:choose>
            <c:when test="${total eq 0}">
                共 ${total+1} 页，当前第 ${pageCurId} 页
            </c:when>
            <c:otherwise>
                共 ${total} 页，当前第 ${pageCurId} 页
            </c:otherwise>
        </c:choose>
        <c:if test="${pageCurId lt total}">
            <a href="/admin/adminLog/showAllUserInfo.do?pageCurId=${pageCurId+1}">下一页</a>
        </c:if>
    </c:if>
</form>
<script language="javascript">
    function yesOrNo() {
        if (confirm("您确定要授予该用户管理员权限吗?")) {
            return true;
        } else
            return false;
    }

    function validateInput() {
        var sUserName = document.queryByName.userName.value;
        if (sUserName == "" || sUserName == null) {
            alert("输入的用户名不能为空，请输入用户名!");
            return false;
        }
    }
</script>
</body>
</html>